package org.codeart.flyweight.demo2;

import java.util.HashMap;
import java.util.Map;

/**
 * 享元工厂类，生产五子棋棋子
 */
public class GobangFactory {

    private static Map<String, GobangFlyweight> pool;

    public GobangFactory() {
        pool = new HashMap<>();
        GobangFlyweight black = new BlackGobang();
        GobangFlyweight white = new WhiteGobang();
        pool.put("black", black);
        pool.put("white", white);
    }

    public GobangFlyweight getGobang(String key) {
        return pool.get(key);
    }

    // 获取唯一享元工厂对象的方法
    public static GobangFactory getInstance() {
        return SingletonHolder.instance;
    }

    private static class SingletonHolder {

        private static final GobangFactory instance = new GobangFactory();
    }
}
